﻿using Clipboard.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clipboard.Tools
{
    public static class EnumHelper
    {
        // 通用方法：将 Enum 转换为 KeyValuePair<int, string> 列表
        public static List<KeyValuePair<int, string>> EnumToKeyValuePairs<T>() where T : Enum
        {
            var enumType = typeof(T);
            var enumValues = Enum.GetValues(enumType).Cast<T>();
            var enumList = new List<KeyValuePair<int, string>>();

            foreach (var value in enumValues)
            {
                var fieldInfo = enumType.GetField(value.ToString());
                var attribute = (EnumDescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(EnumDescriptionAttribute));
                string description = attribute != null ? attribute.Description : value.ToString();
                enumList.Add(new KeyValuePair<int, string>(Convert.ToInt32(value), description));
            }

            return enumList;
        }
    }
}
